import Vue from 'vue'
import App from './App'
// import indexList from 'components/gui-product-list-index.vue'

// Vue.component('gui-product-list-index',indexList)

// Vue.$serverUrl = 'http://taiqiu/api.';
// Vue.$gaodeKey = '0789b60f2e91dc5bbf39de8f22b75a45';

//设置全局变量
Vue.prototype.serverUrl = 'https://api.zhifuby.com';
Vue.prototype.gaodeKey = '300463329d24657926470c8293edb315';
Vue.prototype.test_token =
	'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImtpZCI6ImtleUlkIn0.eyJpc3MiOiJ0YWlxaXUiLCJhdWQiOiJ0YWlxaXUiLCJpYXQiOjE3MTgxNjUzMzUsIm5iZiI6MTcxODE2NTMzNSwiZXhwIjozMzI1NDE2NTMzNSwiZGF0YSI6eyJpZCI6MX19.g8UDCdPWblioa8m7Fsy9Wvin5lKC08MdKbZSjQX1e5s'
Vue.prototype.empty_img = 'https://api.zhifuby.com/static/images/15372054-1f849183cebb80b1.webp'
Vue.prototype.id_card_zheng_img = 'https://api.zhifuby.com/static/images/id_card_zheng.png'
Vue.prototype.id_card_fan_img = 'https://api.zhifuby.com/static/images/id_card_fan.png'



Vue.prototype.token = '';
Vue.prototype.graceJS = require('@/GraceUI5/js/grace.js');



//设置全局方法
Vue.prototype.callMobile = function(mobile) {
	uni.makePhoneCall({
		phoneNumber: phone_number, // 电话号码
		success: function() {
			console.log('拨打电话成功');
		},
		fail: function() {
			uni.showToast({
				title: '拨打电话失败',
				icon: 'error'
			})
		}
	});
}


Vue.prototype.$globalMethod = function() {
	// console.log(2222);

	const pages = getCurrentPages();
	const currentPage = pages[pages.length - 1];
	const pagePath = currentPage.route;



	// 获取数据
	var token = this.graceJS.getStorage('token');
	if (token != false) {


		let _this = this;
		_this.token = token;

		// console.log(pagePath);

		_this.graceJS.get(_this.serverUrl + '/api.user/my_info', {}, {
			token: _this.token
		}, (res) => {
			if (res.code == 0) {
				
				_this.graceJS.setStorage({last_identity:res.data.member_info.last_identity});
				
				console.log(pagePath);
				
				if(pagePath=='pages/index/index'){
					_this.graceJS.setStorage({last_identity:1});
				}
				
				if(pagePath=='pages/index/player_index'){
					_this.graceJS.setStorage({last_identity:3});
				}
				
				if(pagePath=='pages/index/shop_index'){
					_this.graceJS.setStorage({last_identity:5});
				}
				
				var last_identity = _this.graceJS.getStorage('last_identity');
				if(pagePath=='pages/index/index'){
					if(last_identity==3){
						uni.reLaunch({
							url:'/pages/index/player_index'
						})
					}
					
					if(last_identity==5){
						uni.reLaunch({
							url:'/pages/index/shop_index'
						})
					}
				}
				
				if (res.data.member_info.mobile == '') {
					if (pagePath != 'pages/index/index' && pagePath != 'pages/index/login' && pagePath !='pages/index/user_agree' && pagePath != 'pages/index/privacy_agree' && pagePath != 'pages/my/index') {
						uni.reLaunch({
							url: '/pages/index/login'
						})
					}
				}
			}
		})



		return token;
	} else {
		let _this = this;
		uni.getProvider({
			service: 'oauth',
			success: function(res) {

				if (~res.provider.indexOf('weixin')) {
					uni.login({
						provider: 'weixin',
						success: function(loginRes) {


							uni.request({
								url: _this.serverUrl +
									'/api.wechat/login', //仅为示例，并非真实接口地址。
								data: {
									code: loginRes.code
								},
								method: "POST",
								success: (res) => {
									var return_data = res.data;
									if (return_data.code == 0) {

										var token = return_data.data.token;

										_this.graceJS.setStorage({
											token: token
										});


										if (pagePath != 'pages/index/index' && pagePath != 'pages/index/login' && pagePath !='pages/index/user_agree' && pagePath != 'pages/index/privacy_agree') {
											if (return_data.data.is_mobile ==0) {
												uni.reLaunch({
													url: '/pages/index/login'
												})
											}
										}

										uni.reLaunch({
											url: '/pages/index/index'
										})
									} else {
										uni.showToast({
											title: return_data.msg,
											icon: 'error'
										});
									}
								}
							});
						}
					});


				}
			}
		});
	}
}





Vue.config.productionTip = false
App.mpType = 'app'

const app = new Vue({
	...App
})
app.$mount()



 